'use strict';

module.exports = async function factory (app, conf, load) {
   try {
      if (conf.kafka) {
         const Kafka = require('kafka-node');

         app.fs = app.fs || {}
         const client = new Kafka.KafkaClient({
            kafkaHost: conf.kafka.root,
            fromOffset: true
         });
         const producer = new Kafka.HighLevelProducer(client);
         producer.on('error', function (err) {
            app.fs.logger.log('error', "[FS-KAFKA]", err);
         });
         producer.on("ready", function () {
            // console.log('Kafka ready')
         })
         app.fs.kafka = {
            producer: producer,
         };
      }
   } catch (error) {
      console.error(error);
      process.exit(-1);
   }
}
